package 力扣._7_整数反转;

import java.util.Stack;

public class Solution {
    public int reverse(int x) {
        boolean isneg = x < 0;
        if (isneg)
            x = -x;
        long num = 0;
        Stack<Integer> stack = new Stack<>();
        while (x > 0) {
            stack.push(x % 10);
            x /= 10;
        }
        int t = 0;
        while (!stack.isEmpty()) {
            num = (long) (num + stack.pop() * Math.pow(10, t++));
        }
        if(num>Integer.MAX_VALUE)
            return 0;
        if (isneg)
            num = -num;
        return (int) num;
    }

    public static void main(String[] args) {
        int reverse = new Solution().reverse(1534236469);
        System.out.println(reverse);
    }
}
